package test.hxy.mongoSchoolSimple.dao;

import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Repository;
import test.hxy.mongoSchoolSimple.model.Teacher;

@Repository
public class TeacherTenplateDao {

    @Autowired
    MongoTemplate mongoTemplate;
    public void insert(Teacher teacher){
        mongoTemplate.insert(teacher);
    }
    public void delete(String teacherId) {
        Query query = new BasicQuery(new Document("teacherId", teacherId));
        mongoTemplate.remove(query, Teacher.class);
    }
    public void cancelPrincipal(String campusId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("campusId").is(campusId));
        Update update = Update.update("principal", false);
        mongoTemplate.updateMulti(query, update, "teacher");
    }
}
